package com.ict.ms.area.service.api.impl;


import org.apache.ibatis.binding.BindingException;
import org.springframework.stereotype.Service;

import com.ict.ms.area.facade.api.IPointService;
import com.ict.ms.area.facade.model.PointModel;
import com.ict.ms.area.service.dao.IPointDao;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by fcc on 2017/4/26.
 */
@Service("pointService")
public class PointService  implements  IPointService {
    @Resource
    IPointDao pointDao;

    //添加点
    public int addPoint(PointModel point) {
        int ids = 0;
        try {
            ids = pointDao.getidByO(point);
        } catch (BindingException e) {//捕捉为null时候
            pointDao.addPoint(point);
        } catch (Exception e) {
            System.out.println(e + "添加操作失败");
        }
        return ids;
    }

    //删除点
    public int rmPoint(int id) {
        int a = 0;
        try {
            pointDao.rmPoint(id);
        } catch (Exception e) {
            System.out.println("数据库操作失败" + e);
            a = 1;
        }
        return a;
    }

    //更新点信息
    public int updatePoint(PointModel point) {
        int a = 0;
        try {
            pointDao.updatePoint(point);
            a = 1;
        } catch (Exception e) {
            System.out.println("数据库操作失败" + e);
        }
        return a;
    }

    //查询信息
    public PointModel selectPoint(int id) {
        PointModel point;
        try {
            point = pointDao.getPoint(id);
        } catch (Exception e) {
            System.out.println("数据库操作失败" + e);
            point = null;
        }
        return point;
    }

    public List<PointModel> selectPointAll() {
        List<PointModel> list;
        try {
            list = pointDao.getPointAll();
        } catch (Exception e) {
            System.out.println("查询数据库失败" + e);
            list = null;
        }
        return list;
    }

    public int getidByO(PointModel point) {
        int id = 0;
        try {
            id = pointDao.getidByO(point);
        } catch (Exception e) {
            System.out.println("请求连接数据库错误" + e);
        }
        return id;
    }
}
